﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.InterferenceVolume.CUiIVNotificationMgr
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.InterferenceVolume.Res;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.InterferenceVolume;

internal class CUiIVNotificationMgr
{
  private List<CUiIVNotification> m_notifications = new List<CUiIVNotification>();

  internal CUiIVNotificationMgr()
  {
  }

  internal bool HasNotifications => this.m_notifications.Count < 1;

  internal CUiIVNotification LastNotification
  {
    get
    {
      CUiIVNotification lastNotification = (CUiIVNotification) null;
      if (this.HasNotifications)
        lastNotification = this.m_notifications[this.m_notifications.Count - 1];
      return lastNotification;
    }
  }

  internal DialogResult Show(CUiIVNotification notification, string caption)
  {
    DialogResult dialogResult = DialogResult.None;
    CUiIVNotificationMessage message = (CUiIVNotificationMessage) null;
    try
    {
      message = this.GenerateMessage(notification, caption);
    }
    catch (CUiIVInternalLoadStringFailedException ex)
    {
      dialogResult = DialogResult.None;
    }
    catch (CUiIVInternalParamsFormatFailedException ex)
    {
      dialogResult = DialogResult.None;
    }
    if (message != null)
      dialogResult = this.Show(message);
    return dialogResult;
  }

  internal DialogResult Show(CUiIVNotificationMessage message)
  {
    DialogResult dialogResult = DialogResult.None;
    if (message != null)
      dialogResult = TxMessageBox.Show(message.Text, message.Caption, message.Buttons, message.Icon);
    return dialogResult;
  }

  internal bool AddNotification(CUiIVNotification notification)
  {
    bool flag = false;
    if (notification != null)
    {
      this.m_notifications.Add(notification);
      flag = true;
    }
    return flag;
  }

  internal bool RemoveLastNotification()
  {
    bool flag = true;
    if (this.HasNotifications)
      this.m_notifications.RemoveAt(this.m_notifications.Count - 1);
    return flag;
  }

  internal void ClearNotifications() => this.m_notifications.Clear();

  internal CUiIVNotificationMessage GenerateMessage(CUiIVNotification notification, string caption)
  {
    try
    {
      switch (notification.Code)
      {
        case eUiIVNotificationCode.CAN_CREATE_ERR_IDENTICAL_INTERFERENCE_VOLUME_OPERATION_HOLDERS:
          return new CUiIVNotificationMessage(string.Format(CUiIVInterferenceVolumeResourceTable.MSG_CAN_CREATE_ERR_IDENTICAL_INTERFERENCE_VOLUME_OPERATION_HOLDERS, (object) this.InDoubleQuotes(notification.StringParams[0])), caption, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        case eUiIVNotificationCode.CAN_CREATE_ERR_IDENTICAL_INTERFERENCE_VOLUME_PROGRAM_HOLDERS:
          return new CUiIVNotificationMessage(string.Format(CUiIVInterferenceVolumeResourceTable.MSG_CAN_CREATE_ERR_IDENTICAL_INTERFERENCE_VOLUME_PROGRAM_HOLDERS, (object) this.InDoubleQuotes(notification.StringParams[0])), caption, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        case eUiIVNotificationCode.CAN_CREATE_ERR_IDENTICAL_SWEPT_VOLUMES:
          return new CUiIVNotificationMessage(CUiIVInterferenceVolumeResourceTable.MSG_CAN_CREATE_ERR_IDENTICAL_SWEPT_VOLUMES, caption, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        case eUiIVNotificationCode.CAN_CREATE_WARNING_INTERFERENCE_VOLUME_ALREADY_EXIST:
          return new CUiIVNotificationMessage(string.Format(CUiIVInterferenceVolumeResourceTable.MSG_CAN_CREATE_WARNING_INTERFERENCE_VOLUME_ALREADY_EXIST, (object) this.InDoubleQuotes(notification.StringParams[0]), (object) this.InDoubleQuotes(notification.StringParams[1])), caption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
        case eUiIVNotificationCode.CAN_CREATE_WARNING_SWEPT_VOLUME_MISSING_GEOMETRY:
          return new CUiIVNotificationMessage(string.Format(CUiIVInterferenceVolumeResourceTable.MSG_CAN_CREATE_WARNING_SWEPT_VOLUME_MISSING_GEOMETRY, (object) this.InDoubleQuotes(notification.StringParams[0])), caption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
        case eUiIVNotificationCode.CAN_CREATE_WARNING_ALL_SWEPT_VOLUMES_MISSING_GEOMETRY:
          return new CUiIVNotificationMessage(CUiIVInterferenceVolumeResourceTable.MSG_CAN_CREATE_WARNING_ALL_SWEPT_VOLUMES_MISSING_GEOMETRY, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
        case eUiIVNotificationCode.CAN_CREATE_WARNING_BLANKED_SWEPT_VOLUMES:
          return new CUiIVNotificationMessage(CUiIVInterferenceVolumeResourceTable.MSG_CAN_CREATE_WARNING_BLANKED_SWEPT_VOLUMES, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
        case eUiIVNotificationCode.CREATE_ERR_INTERFERENCE_VOLUME_CREATE_FAIL:
          return new CUiIVNotificationMessage(CUiIVInterferenceVolumeResourceTable.MSG_CREATE_ERR_INTERFERENCE_VOLUME_CREATE_FAIL, caption, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        case eUiIVNotificationCode.CREATE_ERR_INTERFERENCE_VOLUME_CALCULATE_FAIL:
          return new CUiIVNotificationMessage(CUiIVInterferenceVolumeResourceTable.MSG_CREATE_ERR_INTERFERENCE_VOLUME_CALCULATE_FAIL, caption, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        case eUiIVNotificationCode.CREATE_WARNING_INTERFERENCE_VOLUME_MISSING_INTERSECTION:
          return new CUiIVNotificationMessage(CUiIVInterferenceVolumeResourceTable.MSG_CREATE_WARNING_INTERFERENCE_VOLUME_MISSING_INTERSECTION, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
        default:
          throw new CUiIVInternalLoadStringFailedException("Missing string for notification code:" + notification.Code.ToString());
      }
    }
    catch (ArgumentOutOfRangeException ex)
    {
      throw new CUiIVInternalParamsFormatFailedException(ex.Message);
    }
    catch (ArgumentNullException ex)
    {
      throw new CUiIVInternalParamsFormatFailedException(ex.Message);
    }
    catch (FormatException ex)
    {
      throw new CUiIVInternalParamsFormatFailedException(ex.Message);
    }
  }

  private bool LogNotification(CUiIVNotification notification)
  {
    throw new NotImplementedException();
  }

  private string InDoubleQuotes(string text) => $"\"{text}\"";
}
